import React, { PureComponent } from 'react'
import Device from './device-detail'
import Bar from './wave-bar'
import Discrete from './discrete'
import Table from 'antd/lib/table'
import Param from './param'
import Log from './log'
import { connect } from 'react-redux'
import { millToString } from '../../util/util'
import { setTitle, scale, tooltip } from '../chart/util/common'

/*印刷机*/
class DeviceInfo extends PureComponent {
    render () {

        const {data} = this.props
        const {logs = [], currentSingleBoard = {}, data: param = {}} = data

        const pieData = {
            title: '设备今日运行状况',
            option: {},
            data: [{
                value: 100,
                name: '正常'
            }, {
                value: 0,
                name: '未完成'
            }, {
                value: 0,
                name: '故障'
            }]
        }

        const boardData = {
            '程序名': currentSingleBoard.programName,
            '任务令': currentSingleBoard.taskId,
            '编码': currentSingleBoard.encode,
            '加工时间': millToString(currentSingleBoard.processDate),
        }

        const columns = [
            {
                title: '项目',
                dataIndex: 'project',
                key: 'project',
            }, {
                title: '数值',
                dataIndex: 'num',
                key: 'num',
            }, {
                title: '状态',
                dataIndex: 'status',
                key: 'status',
            }, {
                title: '范围',
                dataIndex: 'fw',
                key: 'address',
            }
        ]

        const params = []

        params.push({
            project: '第一锡锅温度',
            num: param.firstPanTemperature + '℃',
            status: '正常',
            fw: '290～300℃'
        }, {
            project: '第二锡锅温度',
            num: param.secondPanTemperature,
            status: '未用',
            fw: '36~116N'
        }, {
            project: '第三锡锅温度',
            num: param.thirdPanTemperature + 'mm/s',
            status: '正常',
            fw: '10~30mm/s'
        })

        const preheatingzone = (param.Preheatingzone || [])
        preheatingzone.push({
            Temp_in_low_preheat_11: 342,
            Temp_in_upper_preheat_11: 188,
            Time_in_preheat_11: 70,
            name: '第二预热区'
        })
        const weldzone = param.Weldzone || []

        console.log(preheatingzone)
        const data1 = {
            title: '',
            xAxisData: ['第一预热区', '第二预热区', '第三预热区'],
            yAxisData: (preheatingzone.map((p, i) => {
                console.log(p)
                return [{
                    name: '上预热温度',
                    type: 'bar',
                    label: {
                        normal: {
                            show: false,
                            position: 'top',
                            textStyle: {
                                color: '#fff',
                                fontSize: 12 * scale
                            }
                        }
                    },
                    data: [p.Time_in_preheat_11, 70, 80]
                }, {
                    name: '下预热温度',
                    type: 'bar',
                    label: {
                        normal: {
                            show: false,
                            position: 'top',
                            textStyle: {
                                color: '#fff',
                                fontSize: 12 * scale
                            }
                        }
                    },
                    data: [p.Temp_in_upper_preheat_11, 178, 183]
                }, {
                    name: '预热时间',
                    type: 'bar',
                    yAxisIndex: 1,
                    label: {
                        normal: {
                            show: false,
                            position: 'top'
                        }
                    },
                    data: [p.Temp_in_low_preheat_11, 365, 380]
                }]

            })[0] || [])
        }

        const data2 = {
            title: '',
            xAxisData: ['第一焊接区', '第二焊接区', '第三焊接区'],
            yAxisData: weldzone.map((p, i) => {
                console.log(p)
                return [{
                    name: '上预热温度',
                    type: 'bar',
                    label: {
                        normal: {
                            show: false,
                            position: 'top',
                            textStyle: {
                                color: '#fff',
                                fontSize: 12 * scale
                            }
                        }
                    },
                    data: [p.Temp_Solder_pot_1, 300, 312]
                }, {
                    name: '锡锅温度',
                    type: 'bar',
                    label: {
                        normal: {
                            show: false,
                            position: 'top',
                            textStyle: {
                                color: '#fff',
                                fontSize: 12 * scale
                            }
                        }
                    },
                    data: [p.Temperature_Heating_top_Soldering_1, 155, 161]
                }, {
                    name: '预热时间',
                    type: 'bar',
                    yAxisIndex: 1,
                    label: {
                        normal: {
                            show: false,
                            position: 'top'
                        }
                    },
                    data: [p.Times_in_SU_1, 60, 68]
                }]

            })[0] || []
        }

        return (
            <Device src="../images/business/reflow.png" data={data} currentSingleBoard={boardData} pieData={pieData}>
                <div className="device-res">
                    <div className="device-wave-chart">
                        <Bar data={data1}/>
                    </div>

                    <div className="device-wave-chart">
                        <Bar data={data2}/>
                    </div>
                    <div className="device-wave-data">
                        <Param columns={columns} data={params}/>
                    </div>
                    <div className="device-wave-data">
                        <Log title="设备告警日志" logs={logs}/>
                    </div>
                </div>

            </Device>
        )
    }

}

function mapStoreToProps ({deviceMetrics}) {
    return {
        data: deviceMetrics.get('wave').toJS()
    }
}

export default connect(mapStoreToProps)(DeviceInfo)

